<?php

namespace app\admin\controller;
use app\admin\model\ArithmeticalLog as ArithmeticalLogModel;
use app\admin\model\Member as MembeModel;

class ArithmeticalLog extends Admin
{

    /**
     * 节点产出记录
     * @return \think\response\Json|\think\response\View
     * @throws \think\db\exception\DbException
     */
    function index(){
        if (!$this->request->isPost()){
            return view('index');
        }else{
            $limit  = $this->request->post('limit', 20, 'intval');
            $page = $this->request->post('page', 1, 'intval');
            $order  = $this->request->post('order', '', 'serach_in');	//排序字段
            $sort  = $this->request->post('sort', '', 'serach_in');		//排序方式

            $orderby = ($sort && $order) ? $sort.' '.$order : 'id desc';
            //获取节点产出记录
            $res = ArithmeticalLogModel::getList($page,$limit,[],$orderby);

            foreach ($res['data'] as &$v){
                $member = MembeModel::getDetails($v['mid']);
                $v['username'] = $member['username'].' | '.$v['mid'];
            }

            $data['status'] = 200;
            $data['data'] = $res;
            return json($data);
        }
    }

}